package cn.com.zpark.servlet_context;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @PackageName: cn.com.zpark.servlet_context
 * @ClassName: ServletContextDemo03
 * @Description:
 * @author: RZS
 * @date: 2021/11/10  11:27
 */
@WebServlet("/scd3.html")
public class ServletContextDemo03 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 绑定属性或对象
        // 1、获取context对象
        ServletContext context = getServletContext();
        // 2、往context对象中添加绑定数据
        context.setAttribute("name", "张三");
        System.out.println("绑定数据成功");
    }
}
